package com.audaque.springboot.foshanupload.core.config;

import com.audaque.springboot.foshanupload.core.factory.YamlPropertySourceFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;

/**
 * @author zgb
 * @desc 代码加载yml文件
 * @date 2022-05-02 00:16:02
 */

//@Configuration
public class PropertySourcesPlaceholderConfig {

    //@Bean
    public static PropertySourcesPlaceholderConfigurer properties() {
        PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
        YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
        yaml.setResources(
                new ClassPathResource[] {
                        /** 请求url地址 */
                        //加载不了框架配置，框架要在这之前启动
                        //方式2
                        //new ClassPathResource("config/application-framework.yml")
                });
        pspc.setProperties(yaml.getObject());
        return pspc;
    }
}
